package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Emp;
import cn.wolfcode.domain.PageResult;
import cn.wolfcode.mapper.EmpMapper;
import cn.wolfcode.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;




    @Override
    public PageResult query(String name, Integer gender, Date begin, Date end, Integer page, Integer pageSize) {
        //        int total =empMapper.selAllCount();
//        int start = (page-1)*pageSize;
//        List<Emp> emps = empMapper.selForList(start,pageSize);
        PageHelper.startPage(page, pageSize);
        List<Emp> emps = empMapper.list(name,gender,begin,end);
        Page<Emp> p = (Page<Emp>) emps;
        return new PageResult(p.getTotal(),p.getResult());
    }

    @Override
    public void delete(List<Long> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void add(Emp emp) {
        emp.setCreateTime(new Date());
        emp.setUpdateTime(new Date());
        empMapper.add(emp);
    }

    @Override
    public Emp getById(Long id) {

        return empMapper.getById(id);
    }

    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(new Date());
        empMapper.update(emp);
    }


}
